# -*- coding: utf-8 -*-
"""
Created on Sat Mar  8 21:58:26 2014

@author: nicolas
"""
from nose.tools import *
import logging

# libs to generate tests
from random import *
from numpy import arange, linspace, zeros, sin, pi, max
import itertools

# lib under test
from importfilters import loadfileGage

# Generals test parameters
_multiprocess_can_split_ = True
tolerance = 2E-6   # 0.01% -> i.e; 1e-4
deltaf_Tol = 0.0002

PUFileName="/Users/nicolas/Documents/Logiciels/Python/InstrumLib/trunk/TDO/p120725d.sig"


# test bench init and closing
def setup():
    logging.basicConfig(filename='LibLinx_test.log', level=logging.DEBUG)
    print "Setup Done!"


def teardown():
    print "TEAR DOWN!"


#  Helpers functions
def GenerateRefSignal(FreqRef=54321, sample_rate=500E3, NSamples=1000000):
    data = GenerateRefSignalWithPhase(FreqRef, sample_rate, NSamples, Phase=0)
    return data


#  Helpers functions
def GenerateRefSignalWithPhase(FreqRef=54321, sample_rate=500E3,
                               NSamples=1000000, Phase=0):
    data = zeros((NSamples, 5))
    data[:, 0] = arange(0, NSamples) / sample_rate
    data[:, 1] = sin(data[:, 0] * FreqRef * 2 * pi + Phase)
    return data


def RelativeError(FreqRef, Res):
    return abs(max(Res - FreqRef)) / max(FreqRef)


def AbsError(FreqRef, Res):
    return abs(max(Res - FreqRef))


def test_LoadGage():
    datas = loadfileGage(PUFileName)
    assert len(datas) == 3E7
